package xj.graph2d.app.prop;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

import xj.graph2d.DrawAttr;
import xj.graph2d.RectangleShape;
import xj.graph2d.shapes.ShapeIcon;

public class FillIcon extends ShapeIcon {

  public FillIcon() { 
    this(16, 16, false);
  }

  public FillIcon(int width, int height) { 
    this(width, height, false);
  }

  public FillIcon(int width, int height, boolean border) { 
    super(new RectangleShape(0, 0, width, height), width, height);
    shape.showBorder(border);
    //shape.setFilled(true);
  }

  public void setFilled(boolean filled) { 
    if (shape != null) { 
      shape.setFilled(filled);
    }
  }

  public void setDrawAttr(boolean filled, DrawAttr attr) { 
    setFilled(filled);
    setDrawAttr(attr);
  }

  public void setDrawAttr(DrawAttr attr) { 
    if (attr != null && 
	shape != null) { 
      DrawAttr sattr =  shape.getDrawAttr();
      if (sattr != null) { 
	attr.copyDrawAttr(sattr);
      }
    }
  }

  @Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    super.paintIcon(c, g, x, y);
    if (!shape.isShowBorder()) { 
      Color oldColor = g.getColor();
      g.setColor(Color.lightGray);
      g.draw3DRect(x, y, iconWidth, iconHeight, false);
      g.setColor(oldColor);
    }
  }

}
